package com.zsw.serviceproducer1c.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EurekaClientController {


    @Autowired
    private DiscoveryClient discoveryClient;


    private String name="serviceproducer1c";

    private String port="9010";

    @GetMapping("/client")
    public String test() {
        String services = "总共微服务有: " + discoveryClient.getServices();
        System.out.println(services);
        return services + "当前的服务端是 ["+name+"],该服务启用负责均衡,当前端口："+port;
    }

    @GetMapping("/hi/{id}")
    public String hi(@PathVariable String id) throws Exception {

        if("1".equals(id)){
            throw new Exception("id等于1，抛异常，查看消费端的异常信息，降级处理");
        }

        String message = "恭喜访问成功，参数["+id+"]，当前的服务端是 ["+name+"],该服务启用负责均衡,当前端口："+port;
        System.out.println(message);
        return message;
    }
}
